using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
namespace MicroMsg.Scene.ChatRoom
{
	public class NetSceneGroupCard : NetSceneBaseEx<GroupCardRequest, GroupCardResponse, GroupCardRequest.Builder>
	{
		private const string TAG = "NetSceneGroupCard";
		private const uint MM_GROUPCARD_ADD = 1u;
		public bool doScene(string groupNickName, string groupUserName, List<Contact> contactList)
		{
			if (contactList != null && contactList.get_Count() != 0 && !string.IsNullOrEmpty(groupNickName) && !string.IsNullOrEmpty(groupUserName))
			{
				base.beginBuilder();
				this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
				this.mBuilder.OpCode = 1u;
				this.mBuilder.GroupNickName = groupNickName;
				this.mBuilder.GroupUserName = groupUserName;
				using (List<Contact>.Enumerator enumerator = contactList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Contact current = enumerator.get_Current();
						this.mBuilder.MemberListList.Add(RoomInfo.CreateBuilder().SetUserName(Util.toSKString(current.strUsrName)).SetNickName(Util.toSKString(current.strNickName)).Build());
					}
				}
				this.mBuilder.MemberCount = (uint)contactList.get_Count();
				this.mSessionPack.mConnectMode = 2;
				this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/addgroupcard";
				base.endBuilder();
				return true;
			}
			Log.smethod_5("NetSceneGroupCard", "doScene,invalid input para");
			return false;
		}
		protected override void onFailed(GroupCardRequest request, GroupCardResponse response)
		{
			Log.smethod_1("NetSceneGroupCard", "send NetSceneGroupCard failed");
			EventCenter.postEvent(EventConst.ON_NETSCENE_CHATROOM_GROUPCARD_ERR, null, null);
		}
		protected override void onSuccess(GroupCardRequest request, GroupCardResponse response)
		{
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneGroupCard", "send NetSceneGroupCard failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_CHATROOM_GROUPCARD_ERR, null, null);
				return;
			}
			if (!ChatRoomMgr.addGroupCardContact(request, response))
			{
				Log.smethod_1("NetSceneGroupCard", "send addGroupCardContact failed ");
				EventCenter.postEvent(EventConst.ON_NETSCENE_CHATROOM_GROUPCARD_ERR, null, null);
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_CHATROOM_GROUPCARD_SUCCESS, null, null);
		}
	}
}
